<template>
    <div class="out-position-manage">
        <div class="personal-manage-title">
            敏感词管理
            <div class="out-position-manage-title-button">
                <!-- <el-button type="primary" size="mini" @click="intData">初始化敏感词库</el-button> -->
                <el-button type="primary" size="mini" @click="reIntData">重新加载敏感词库</el-button>
                <el-button type="primary" size="mini" @click="addOutPosition" plain>新增</el-button>
            </div>
        </div>
        <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div class="report-table-form1-item" style="width: 200px">
                    <el-input
                        v-model="searchKeyWord"
                        placeholder="请输入搜索内容"
                        size="small"
                        suffix-icon="el-icon-search"
                    ></el-input>
                </div>
                <el-button type="primary" size="small" @click="cutArray">查询</el-button>
            </div>
        </div>
        <div class="personal-manage-table-wrapper">
            <el-table
                :data="showList"
                :header-cell-style="headerCellStyle"
                stripe
                border
                size="small"
                style="width: 100%"
            >
                <el-table-column prop="userName" label="序号" width="50">
                    <template slot-scope="scope">{{scope.$index + 1 + 10 * (position - 1)}}</template>
                </el-table-column>
                <el-table-column prop="id" label="id"></el-table-column>
                <el-table-column prop="keywords" label="关键词"></el-table-column>
                <el-table-column label="操作" width="150">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="danger"
                            @click="checkRemove(scope.$index, scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <el-dialog title="新增敏感词" :visible.sync="dialogFormVisible" width="400px">
            <el-form label-position="right" size="small">
                <el-form-item label="敏感词" :label-width="formLabelWidth">
                    <el-input v-model="keywords" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelDialog" size="small">取消</el-button>
                <el-button type="primary" @click="okDialog" size="small">确定</el-button>
            </div>
        </el-dialog>

        <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
            <span>确认删除</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelRemove" size="small">取消</el-button>
                <el-button type="primary" @click="okRemove" size="small">确定</el-button>
            </span>
        </el-dialog>
        <div class="pay-set-wrapper-table-block" v-show="showList.length > 0">
            <div class="pay-set-wrapper-table-block-in">
                <el-pagination
                    background
                    :current-page.sync="position"
                    @current-change="handleCurrentChange"
                    :page-size="10"
                    layout="total, prev, pager, next"
                    :total="totalNum"
                ></el-pagination>
            </div>
        </div>
        <div class="page-padding" v-show="showList.length > 0"></div>
        <div class="page-padding-gray"></div>
    </div>
</template>

<script type="text/ecmascript-6">
// 1、一页10条数据
// 2、勾选框和下拉框和输入框做判断
export default {
    data: function () {
        return {
            totalNum: 0, // 出品类型总数
            showList: [], // 展示列表
            position: 1,

            keywords: '',
            searchKeyWord: '',

            formLabelWidth: '120px',

            dialogFormVisible: false,
            dialogFormVisible2: false,
            dialogVisible: false,

            nowRemoveRow: {}
        }
    },
    components: {},
    mounted () {
        this.cutArray()
    },
    watch: {
        position () {
            this.cutArray()
        }
    },
    created () {},
    methods: {
        intData () {
            let params = {
                params: {
                }
            }
            this.$http
                .get(this.$store.state.IP + 'worldfilter/garbage/init', params)
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        console.log('调用初始化返回')
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            this.cutArray()
                        }
                        if (response.ret !== '0') {
                            console.log('调用初始化失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        },
        reIntData () {
            let params = {
                params: {
                }
            }
            this.$http
                .get(this.$store.state.IP + 'worldfilter/garbage/resetInit', params)
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        console.log('调用初始化返回')
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            this.cutArray()
                        }
                        if (response.ret !== '0') {
                            console.log('调用初始化失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        },
        getPage () {
            let params = {
                params: {
                    keyword: this.searchKeyWord,
                    page: this.position - 1, // 页数
                    num: 10 // 一页显示数量
                }
            }
            this.$http
                .get(this.$store.state.IP + 'worldfilter/garbage/garbageList', params)
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        console.log('调用敏感词列表返回')
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            this.showList = response.res.list
                            this.totalNum = response.res.total
                        }
                        if (response.ret !== '0') {
                            console.log('调用敏感词列表失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        },

        okDialog () {
            this.dialogFormVisible = false
            let params = {
                params: {
                    key: this.keywords
                }
            }
            this.$http
                .get(this.$store.state.IP + 'worldfilter/garbage/addGarbage', params)
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        console.log('调用新增敏感词返回')
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            console.log('调用新增敏感词成功')
                            this.cutArray()
                        }
                        if (response.ret !== '0') {
                            console.log('调用新增敏感词失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
            // 此处调用新增接口
        },
        cancelDialog () {
            this.dialogFormVisible = false
            this.keywords = ''
        },
        addOutPosition () {
            this.dialogFormVisible = true
            this.keywords = ''
        },

        checkRemove (index, row) {
            this.nowRemoveRow = row
            this.dialogVisible = true
        }, // 删除按钮
        okRemove () {
            this.dialogVisible = false
            let params = {
                params: {
                    key: this.nowRemoveRow.keywords
                }
            }
            this.$http
                .get(this.$store.state.IP + 'worldfilter/garbage/deleteGarbage', params)
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        console.log('调用删除敏感词返回')
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            console.log('调用删除敏感词成功')
                            this.cutArray()
                        }
                        if (response.ret !== '0') {
                            console.log('调用删除敏感词失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        }, // 删除确认框确认
        cancelRemove () {
            this.nowRemoveRow = {}
            this.dialogVisible = false
        }, // 删除确认框取消

        handleCurrentChange (val) {
            this.position = val
        },
        cutArray () {
            //				this.showList = this.tableData.slice((pos - 1) * 10, (pos - 1) * 10 + 10)
            this.getPage()
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
.out-position-manage
    width: 100%
    background: #fff
    min-height: calc(100vh - 65px)

    .personal-manage-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background: #f1f0f5
        position: relative

        .out-position-manage-title-button
            position: absolute
            right: 0
            top: 0

     .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing border-box
        background #fff
        overflow hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align left

                &.big
                    margin-right: 100px

    .pay-set-wrapper-table-block
        width: 100%
        padding-top: 22px
        height: 50px
        background: #fff
        box-sizing: border-box

        .pay-set-wrapper-table-block-in
            float: right
            padding-right: 17px

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .personal-manage-table-wrapper
        width: 100%
</style>
